
# Definition for Employee.
class Employee(object):
    def __init__(self, id, importance, subordinates):
        self.id = id
        self.importance = importance
        self.subordinates = subordinates


class Solution(object):
    def getImportance(self, employees, id):
        """
        :type employees: List[Employee]
        :type id: int
        :rtype: int
        """
        d = {}
        s = {}
        t = 0
        for employ in employees:
            d[employ.id] = employ.subordinates
            s[employ.id] = employ.importance
        now = [id]
        while now:
            next_st = []
            for item in now:
                t += s[item]
                next_st += d[item]
            now = next_st
        return t